package com.battle.pojo.enums.authorizedLog;

import lombok.AllArgsConstructor;
import lombok.Getter;
import nirvana.core.domains.enums.Enums;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Joseph.Li
 * @author joseph.li@king-v.com
 * Created in 2022-06-16 23:42
 * <p>
 * 授权操作类型
 */
@Getter
@AllArgsConstructor
public enum AuthorizeOperationEnum implements Enums {

    AUTHORIZE(0, "授予权限"),
    BAN(1, "禁用权限");
    private Integer id;
    private String name;


    private static Map<Integer, String> map = Collections.EMPTY_MAP;


    /**
     * 获取对应名称
     * @param id
     * @return
     */
    public static String getNameById(Integer id) {
        if (CollectionUtils.isEmpty(map)) {
            AuthorizeOperationEnum[] values = AuthorizeOperationEnum.values();
            List<AuthorizeOperationEnum> list = Arrays.asList(values);
            map = list
                    .stream()
                    .collect(Collectors.toMap(AuthorizeOperationEnum::getId, AuthorizeOperationEnum::getName));
        }
        return map.get(id);
    }

}
